#!/bin/sh
#
# This is the configuration script for regression testing
#

. ${1}/config

if test "x@db_password@" = "x"; then
  PASSWD=
else
  PASSWD="-Ddb-password=@db_password@"
fi

if [ -z "${CFLAGS}" ]; then
   #CFLAGS="-g -O2 -Wall"
   CFLAGS="-g -Wall"
   export CFLAGS
fi

if [ -d build ] ; then
  echo  build exist...
else
   mkdir build
fi
cd build

if [ -f CMakeCache.txt  ] ; then
  echo  "CMakeCache.txt exist, not calling cmake"
else
   cmake -P ../../write_version_files.cmake
   cmake  ../../core \
      -DCMAKE_VERBOSE_MAKEFILE=ON \
      -DCMAKE_INSTALL_PREFIX:PATH=${1}/usr \
      -DCMAKE_INSTALL_LIBDIR:PATH=${1}/usr/lib \
      -DINCLUDE_INSTALL_DIR:PATH=${1}/usr/include \
      -DLIB_INSTALL_DIR:PATH=${1}/usr/lib \
      -DSYSCONF_INSTALL_DIR:PATH=${1}/etc \
      -DSHARE_INSTALL_PREFIX:PATH=${1}/usr/share \
      -DBUILD_SHARED_LIBS:BOOL=ON \
    -Dbindir=${1}/bin \
    -Dsbindir=${1}/bin \
    -Dlibdir=${1}/bin \
    -Dsysconfdir=${1}/bin \
    -Dscriptdir=${1}/bin \
    -Dconfdir=${1}/bin \
    -Dmandir=${1}/bin \
    -Ddocdir=${1}/bin/html \
    -Dhtmldir=${1}/bin/html \
    -Dlogdir=${1}/working \
    -Dpiddir=${1}/working \
    -Dsubsys-dir=${1}/working \
    -Dplugindir=${1}/bin/plugins \
    -Dlockmgr=yes \
    -Dworkingdir=${1}/working \
    -Darchivedir=${1}/tmp \
    -Ddump_email=${EMAIL} \
    -Djob_email=${EMAIL} \
    -Dsmtp_host=${SMTP_HOST} \
    -Ddb_name=@db_name@ \
    -Ddb_user=@db_user@ \
    ${PASSWD} \
    ${OPENSSL} \
    ${SCSICRYPTO} \
    ${TESTPLUGIN} \
    ${WHICHDB} \
    -Dbaseport=${BASEPORT}\
    ${DEVELOPER}\
    ${COVERAGE} \
    -Ddynamic-cats-backends=yes \
    -Ddynamic-storage-backends=yes \
    ${TRAYMON}\
    -Ddefault_db_backend="XXX_REPLACE_WITH_DATABASE_DRIVER_XXX" \
    ${VERSION_STRING}

fi

LD_LIBRARY_PATH=${1}/bin:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH

cd ..

exit 0
